package com.xishu.entity.shop;

import com.xishu.annotation.dao.DefaultValue;
import com.xishu.annotation.dao.FieldMapping;
import com.xishu.annotation.dao.Search;
import com.xishu.annotation.lang.Lang;
import com.xishu.annotation.oplog.OplogAnnotation;
import com.xishu.entity.AbstractEntity;
import com.xishu.entity.NameAndId;
import com.xishu.entity.ShopItem;
import com.xishu.entity.oplog.OpName;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity(name = "catalog")
@Table(indexes = {@Index(columnList = "shopId")})
public class Catalog extends ShopItem implements OpName {
    private static final long serialVersionUID = 2245021000746549341L;

    @Transient
    private String opName;

    @ApiModelProperty(value = "品类名称")
    @OplogAnnotation(fieldName = "品类名称")
    @Lang(key = "name")
    private String name;

    @ApiModelProperty(value = "品类名称")
    @OplogAnnotation(fieldName = "品类名称")
    @Lang(key = "name")
    private String name_zh;

    @ApiModelProperty(value = "品类名称")
    @OplogAnnotation(fieldName = "品类名称")
    @Lang(key = "name")
    private String name_en;

    @ApiModelProperty(value = "归属的餐厅公司")
    private Long companyId;

    @ApiModelProperty(value = "归属的分店")
    private Long shopId;

    @ApiModelProperty(value = "配置的时间范围")
    @FieldMapping(desField = "timeConfigJson", serialize = true)
    @Transient
    @DefaultValue(defaultValue = "")
    private List<TimeConfig> timeConfigList;

    @ApiModelProperty(value = "配置的时间范围")
    @FieldMapping(desField = "timeConfigList", serialize = false, genericType = "com.xishu.entity.shop.TimeConfig")
    @Column(length = 1024)
    @OplogAnnotation(fieldName = "配置的时间范围")
    private String timeConfigJson;

    @ApiModelProperty(value = "排序")
    private Long showOrder;

    @Transient
    @ApiModelProperty(value = "适用的场景")
    @FieldMapping(desField = "sceneJson", serialize = true)
    private List<NameAndId> sceneList = new ArrayList<>();

    @ApiModelProperty(value = "适用的场景")
    @FieldMapping(desField = "sceneList", serialize = false, genericType = "com.xishu.entity.NameAndId")
    @Column(length = 2048)
    private String sceneJson;

    @ApiModelProperty(value = "实时过滤场景")
    @Transient
    @Search(ignore = true)
    private Long filterSceneId;

    @Transient
    @Search(ignore = true)
    @ApiModelProperty(value = "过滤在线的菜品")
    private Boolean filterOnlineItem;

    public Boolean getFilterOnlineItem() {
        return filterOnlineItem;
    }

    public void setFilterOnlineItem(Boolean filterOnlineItem) {
        this.filterOnlineItem = filterOnlineItem;
    }

    public Long getFilterSceneId() {
        return filterSceneId;
    }

    public void setFilterSceneId(Long filterSceneId) {
        this.filterSceneId = filterSceneId;
    }

    public List<NameAndId> getSceneList() {
        return sceneList;
    }

    public void setSceneList(List<NameAndId> sceneList) {
        this.sceneList = sceneList;
    }

    public String getSceneJson() {
        return sceneJson;
    }

    public void setSceneJson(String sceneJson) {
        this.sceneJson = sceneJson;
    }

    public String getName() {
        return name;
    }

    @Override
    public String opType() {
        return "品类";
    }

    @Override
    public String[] fieldName() {
        return new String[]{"shopId", "name"};
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

    public Long getShopId() {
        return shopId;
    }

    public void setShopId(Long shopId) {
        this.shopId = shopId;
    }

    public Long getShowOrder() {
        return showOrder;
    }

    public void setShowOrder(Long showOrder) {
        this.showOrder = showOrder;
    }

    public List<TimeConfig> getTimeConfigList() {
        return timeConfigList;
    }

    public void setTimeConfigList(List<TimeConfig> timeConfigList) {
        this.timeConfigList = timeConfigList;
    }

    public String getTimeConfigJson() {
        return timeConfigJson;
    }

    public void setTimeConfigJson(String timeConfigJson) {
        this.timeConfigJson = timeConfigJson;
    }

    @Override
    public String getOpName() {
        return opName;
    }

    @Override
    public void setOpName(String opName) {
        this.opName = opName;
    }

    public String getName_zh() {
        return name_zh;
    }

    public void setName_zh(String name_zh) {
        this.name_zh = name_zh;
    }

    public String getName_en() {
        return name_en;
    }

    public void setName_en(String name_en) {
        this.name_en = name_en;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Catalog{");
        sb.append("id = ").append(id).append('\'');
        sb.append("opName='").append(opName).append('\'');
        sb.append(", name='").append(name).append('\'');
        sb.append(", name_zh='").append(name_zh).append('\'');
        sb.append(", name_en='").append(name_en).append('\'');
        sb.append(", companyId=").append(companyId);
        sb.append(", shopId=").append(shopId);
        sb.append(", timeConfigList=").append(timeConfigList);
        sb.append(", timeConfigJson='").append(timeConfigJson).append('\'');
        sb.append(", showOrder=").append(showOrder);
        sb.append(", sceneList=").append(sceneList);
        sb.append(", sceneJson='").append(sceneJson).append('\'');
        sb.append(", filterSceneId=").append(filterSceneId);
        sb.append(", filterOnlineItem=").append(filterOnlineItem);
        sb.append('}');
        return sb.toString();
    }
}
